/**
 * 根据类型获取文章列表
 */
bangkeapp.factory('articalService', 
['$http', '$q', 'userinfoService', 'url', 
function($http, $q, userinfoService, url) {
    var getarticallist = function(artical, page, pagesize) {
		var result = {};
		var data = userinfoService.getData();
		data.request.body.page = page;
		data.request.body.pagesize = pagesize;
		data.request.body.artical = artical;

		var deferred = $q.defer();
		var promise = deferred.promise;
		var progress;
		// 查询
		$http({
			method: "JSONP",
			url: url + "/artical/query?callback=JSON_CALLBACK",
			params: {
				"body": angular.toJson(data)
			}
		}).success(function(response) {

			if("M" == response.Response.Header.ResponseCode &&
				response.Response.Body.Response.length > 0) {
				result = response.Response.Body;
			} else {
				progress = response.Response.Header.MsgList[0];
			}
			deferred.notify(progress);
			deferred.resolve(result);
		})
		.error(function(error) {
			deferred.reject(error);
		});
		return promise;
	}
    
	var clicknum = function(artical) {
		var result = {};
		var data = userinfoService.getData();
		data.request.body.artical = artical;

		var deferred = $q.defer();
		var promise = deferred.promise;
		var progress;
		// 
		$http({
			method: "JSONP",
			url: url + "/artical/saveClickamount?callback=JSON_CALLBACK",
			params: {
				"body": angular.toJson(data)
			}
		}).success(function(response) {

			if("M" == response.Response.Header.ResponseCode){
				progress = true;
			} else {
				progress = false;
			}
			deferred.notify(progress);
			deferred.resolve(result);
		})
		.error(function(error) {
			deferred.reject(error);
		});
		return promise;
	}
    return {
        articallist: getarticallist,
        clicknum: clicknum
    };
}]);